package com.projx.accounting.service;

import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

@Service
public class AuthService {
    private final Map<String, String> tokenToUser = new ConcurrentHashMap<>();

    public String createTokenForUser(String userId) {
        String token = UUID.randomUUID().toString();
        tokenToUser.put(token, userId);
        return token;
    }

    public Optional<String> getUserIdForToken(String token) {
        return Optional.ofNullable(tokenToUser.get(token));
    }

    public void revokeToken(String token) {
        tokenToUser.remove(token);
    }
}
